package com.exigen.perflabstat.dao.jpa;

import java.util.List;

import javax.persistence.Query;

import com.exigen.perflabstat.base.GenericJPADAO;
import com.exigen.perflabstat.dao.ProjectNameDao;
import com.exigen.perflabstat.models.ProjectName;

public class ProjectNameJpaDao extends GenericJPADAO<ProjectName, Long> implements ProjectNameDao {

	public ProjectNameJpaDao() {
		super(ProjectName.class);
	}

	@SuppressWarnings({ "unchecked", "unused" })
	public List<ProjectName> allProjectNames() {
		
		ProjectName projectName = null;
		
		Query query = getEntityManager().createQuery("select project from ProjectName project");
		
		List<ProjectName> result = query.getResultList();
		
		return result;
	}

	@SuppressWarnings("unchecked")
	public ProjectName findByProjectName(String projectName) {
		
		ProjectName project = null;
		
		Query query = getEntityManager().createQuery("select project from ProjectName project where project.PROJECT_NAME = :projectName");
		query.setParameter("projectName", projectName);
		query.setMaxResults(1);
		
		List<ProjectName> result = query.getResultList();
		
		if(result.isEmpty())return null;
		
		project = result.get(0);
		
		return project;
	}
	
	

}
